package cn.train.controler;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.train.model.UserTable;
import cn.train.service.UserTableService;

@WebServlet("/RegAjaxServlet")
public class RegAjaxServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		String idcard=req.getParameter("IDCard");
		String uname=req.getParameter("UserName");
		
		UserTableService userService=new UserTableService();
		
		PrintWriter out =resp.getWriter();
		List<UserTable> list=userService.getAll();
		int m=0;
		for (UserTable u: list) {
			if(idcard!=null){				
				if(idcard.equals(u.getIdcard())){
					m=1;				
				}else{
					m=2;
				}				
			}
			if(uname!=null){
				if(uname.equals(u.getUname())){
					m=1;
				}else{
					m=2;
				}
			}
		}
		out.print(m);
		}
		
		
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}
}
